#include <chrono>
#include <iostream>
#include <map>
#include <mutex>
#include <string>
#include <thread>

std::map<std::string, std::string> g_pages;
std::mutex g_pages_mutex;

void save_page(const std::string &info) {
  std::cout << "Sleep 2s to insert data " << info << "\n";
  std::this_thread::sleep_for(std::chrono::seconds(2));

  std::lock_guard<std::mutex> guard(g_pages_mutex);
  g_pages["info"] = info;
}

int main() {
  std::thread t1(save_page, "foo");
  std::thread t2(save_page, "bar");
  t1.join();
  t2.join();

  for (const auto &pair : g_pages) {
    std::cout << pair.first << " => " << pair.second << '\n';
  }
}
